/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.common;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Carmela
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class PersonaManager implements PersonaManagerLocal {
    @PersistenceContext(unitName = "E-Market-ejbPU")
    private EntityManager em;

    @Override
    public boolean isPersonaRegistrata(String codiceFiscale) {
        if(codiceFiscale==null){
            throw new NullPointerException();
        }
        boolean res=false;
        Query q=em.createNamedQuery("persona.cercaPerCodiceFiscale");
        q.setParameter(1, codiceFiscale);
        if(!q.getResultList().isEmpty()){
            res=true;
        }
        return res;
    }

}
